import Vue from 'vue'
import Router from 'vue-router'
import home from '@/pages/home'
import Login from '@/pages/system/login'
import Preview from '@/pages/Preview'

import SelectCompany from '@/pages/SelectCompany'
Vue.use(Router)

export const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/home',
    name: 'home',
    component: home,
  },
  {
    path: '/login',
    name: 'login', // 路由名称
    component: Login // 组件对象
  },

  {
    path: '/SelectCompany',
    name: 'SelectCompany', // 路由名称
    component: SelectCompany // 组件对象
  },

  {
    path: '/menu/menuManage',
    component: home,
    hidden: true,
    children: [
      {
        path: '/Preview',
        name: '公告资讯详情', // 路由名称
        component: Preview // 组件对象
      },
      {
        path: '/print',
        name: 'print', // 路由名称
        component: () => import('@/pages/print')
      },
      {
        path: '/switchExamine',
        component: () => import('@/pages/switchExamine')

      },
      {
        path: '/initializationHome',
        component: () => import('@/pages/initializationHome')

      },

      {
        path: '/menu/menuManage',
        component: () => import('@/pages/system/menu/menuManage')

      },
      {

        path: '/user/userManage',
        component: () => import('@/pages/user/userManage')

      },
      // 部门列表
      {
        path: '/department/departmentManage',
        component: () => import('@/pages/department/departmentManage')
      },
      //岗位列表
      {
        path: '/department/postList',
        component: () => import('@/pages/department/postList')
      },
      {

        path: '/role/roleManage',
        component: () => import('@/pages/role/roleManage')

      },
      {

        path: '/device/deviceManage',
        component: () => import('@/pages/device/deviceManage')

      },
      {

        path: '/device/deviceInsert',
        component: () => import('@/pages/device/deviceInsert')

      },
      {

        path: '/parameter/parameterManage',
        component: () => import('@/pages/parameter/parameterManage')

      },
      {

        path: '/parameter/parameterInsert',
        component: () => import('@/pages/parameter/parameterInsert')

      },
      {

        path: '/maintenance',
        component: () => import('@/pages/maintenance')

      },
      {

        path: '/maintenance/insert',
        component: () => import('@/pages/maintenance/insert')

      },
      {

        path: '/population/management',
        component: () => import('@/pages/population/management')

      },
      {

        path: '/population/ResidentInformation',
        component: () => import('@/pages/population/ResidentInformation')

      },
      {

        path: '/population/populationInsert',
        component: () => import('@/pages/population/populationInsert')

      },
      {

        path: '/user/userBinding',
        component: () => import('@/pages/user/userBinding')

      },
      {

        path: '/population/populationBinding',
        component: () => import('@/pages/population/populationBinding')

      },
      {
        path: '/population/detail',
        component: () => import('@/pages/population/detail')
      },
      {

        path: '/agency/management',
        component: () => import('@/pages/agency/management')

      },
      {

        path: '/agency/agencyInsert',
        component: () => import('@/pages/agency/agencyInsert')

      },
      {

        path: '/agency/agencyBinding',
        component: () => import('@/pages/agency/agencyBinding')

      },
      {
        path: '/agency/agencyDetail',
        component: () => import('@/pages/agency/agencyDetail')
      },
      // 机构管理
      {
        path: '/institution/inManagement',
        component: () => import('@/pages/institution/inManagement')
      },
      {
        path: '/institution/institutionInsert',
        component: () => import('@/pages/institution/institutionInsert')
      },
      {
        path: '/institution/institutionBinding',
        component: () => import('@/pages/institution/institutionBinding')
      },
      {
        path: '/institution/institutionDetail',
        component: () => import('@/pages/institution/institutionDetail')
      },
      // 小区管理
      {
        path: '/residential/reManagement',
        component: () => import('@/pages/XiaoQuAll/residential/reManagement')
      },
      {
        path: '/residential/reInsert',
        component: () => import('@/pages/XiaoQuAll/residential/reInsert')
      },
      {
        path: '/residential/reBinding',
        component: () => import('@/pages/XiaoQuAll/residential/reBinding')
      },
      {
        path: '/residential/reDetail',
        component: () => import('@/pages/XiaoQuAll/residential/reDetail')
      },
      // 楼宇管理
      {
        path: '/building/buManagement',
        component: () => import('@/pages/XiaoQuAll/building/buManagement')
      },
      {
        path: '/building/buInsert',
        component: () => import('@/pages/XiaoQuAll/building/buInsert')
      },
      {
        path: '/building/buBinding',
        component: () => import('@/pages/XiaoQuAll/building/buBinding')
      },
      {
        path: '/building/buDetail',
        component: () => import('@/pages/XiaoQuAll/building/buDetail')
      },
      // 房间管理
      {
        path: '/room/roomManagement',
        component: () => import('@/pages/XiaoQuAll/room/roomManagement')
      },
      {
        path: '/room/roomInsert',
        component: () => import('@/pages/XiaoQuAll/room/roomInsert')
      },
      {
        path: '/room/roomBinding',
        component: () => import('@/pages/XiaoQuAll/room/roomBinding')
      },
      {
        path: '/room/roomDetail',
        component: () => import('@/pages/XiaoQuAll/room/roomDetail')
      },
      // 报事
      {
        path: '/events/eventsManage',
        component: () => import('@/pages/events/eventsManage')
      },
      {
        path: '/events/eventDispatch',
        component: () => import('@/pages/events/eventDispatch')
      },
      {
        path: '/events/eventsAdd',
        component: () => import('@/pages/events/eventsAdd')
      },
      {
        path: '/events/eventsDetail',
        component: () => import('@/pages/events/eventsDetail')
      },
      {
        path: '/workOrder/workUpdate',
        component: () => import('@/pages/workOrder/workUpdate')
      },
      {
        path: '/workOrder/workManage',
        component: () => import('@/pages/workOrder/workManage')
      },
      {
        path: '/workOrder/workDetail',
        name: '工单详情',
        component: () => import('@/pages/workOrder/workDetail')
      },

      // 服务管理
      {
        path: '/ServiceManagement/List',
        component: () => import('@/pages/ServiceManagement/List')
      },

      // 消息列表
      {
        path: '/message/List',
        component: () => import('@/pages/message/messageList')
      },
      //公告发布
      {
        path: '/webNotice/List',
        component: () => import('@/pages/webNotice/NoticeList')
      },
      //公告审批列表
      {
        path: '/webNotice/NoticeShenPiList',
        component: () => import('@/pages/webNotice/NoticeShenPiList')
      },
      //公告审批
      {
        path: '/webNotice/NoticeShenPi',
        name: '公告审批',
        component: () => import('@/pages/webNotice/NoticeShenPi')
      },
      //资讯发布
      {
        path: '/information/List',
        component: () => import('@/pages/information/informationList')
      },
      //资讯审批列表
      {
        path: '/information/informationShenPiList',
        component: () => import('@/pages/information/informationShenPiList')
      },
      //资讯审批
      {
        path: '/information/informationShenPi',
        name: '资讯审批',
        component: () => import('@/pages/information/informationShenPi')
      },
      // 晨会管理
      {
        path: '/morningMeeting/morningMeetingList',
        component: () => import('@/pages/morningMeeting/morningMeetingList')
      },
      // 晨会管理新增
      {
        path: '/morningMeeting/morningMeetingAdd',
        component: () => import('@/pages/morningMeeting/morningMeetingAdd')
      },
      // 合同管理列表
      {
        path: '/contract/contractList',
        component: () => import('@/pages/contract/contractList')
      },
      // 合同管理新增
      {
        path: '/contract/contractAdd',
        component: () => import('@/pages/contract/contractAdd')
      },
      // 合同管理预览详情
      {
        path: '/contract/contractDetail',
        component: () => import('@/pages/contract/contractDetail')
      },
      // 服务管理
      {
        path: '/facility/list',
        component: () => import('@/pages/facility/list')
      },
      // 服务新增
      {
        path: '/facility/facilityAdd',
        component: () => import('@/pages/facility/facilityAdd')
      },
      // // 电话模块
      // {
      //   path: '/phone/phoneList',
      //   component: () => import('@/pages/phone/phoneList')
      // },
      // 电话总览模块
      {
        path: '/phone/phoneOverview',
        component: () => import('@/pages/phone/phoneOverview')
      },
      // 审批新增/修改
      {
        path: '/examine/examineAdd',
        component: () => import('@/pages/examine/examineAdd')
      },
      // 审批列表
      {
        path: '/examine/examineList',
        component: () => import('@/pages/examine/examineList')
      },
      // 发票列表
      {
        path: '/invoice/invoiceList',
        component: () => import('@/pages/invoice/invoiceList')
      },
      // 发票新增/修改
      {
        path: '/invoice/invoiceAdd',
        component: () => import('@/pages/invoice/invoiceAdd')
      },
      // 发票详情
      {
        path: '/invoice/invoiceDetail',
        component: () => import('@/pages/invoice/invoiceDetail')
      },
      // 入伙登记 列表
      {
        path: '/Admission/AdmissionList',
        component: () => import('@/pages/customer/Admission/AdmissionList')
      },
      // 入伙登记 新增
      {
        path: '/Admission/AdmissionAdd',
        component: () => import('@/pages/customer/Admission/AdmissionAdd')
      },
      // 入伙登记 详情
      {
        path: '/Admission/AdmissionDetail',
        component: () => import('@/pages/customer/Admission/AdmissionDetail')
      },
      // 过户登记 列表
      {
        path: '/Transfer/TransferList',
        component: () => import('@/pages/customer/Transfer/TransferList')
      },
      // 过户登记 新增
      {
        path: '/Transfer/TransferAdd',
        component: () => import('@/pages/customer/Transfer/TransferAdd')
      },
      // 过户登记 详情
      {
        path: '/Transfer/TransferDetail',
        component: () => import('@/pages/customer/Transfer/TransferDetail')
      },
      // 客户迁入迁出
      {
        path: '/MovingInAndOut/MovingInAndOutList',
        component: () => import('@/pages/customer/MovingInAndOut/MovingInAndOutList')
      },
      // 用户管理
      {
        path: '/customerManag/List',
        component: () => import('@/pages/customer/customerManag/List')
      },
      // 用户详情
      {
        path: '/customerManag/Detail',
        component: () => import('@/pages/customer/customerManag/Detail')
      },

      // 车辆管理
      {
        path: '/car/carManagement',
        component: () => import('@/pages/car/car/carManagement')
      },
      // 车辆详情
      {
        path: '/car/carDetail',
        component: () => import('@/pages/car/car/carDetail')
      },
      // 车辆信息
      {
        path: '/car/carInformation',
        component: () => import('@/pages/car/car/carInformation')
      },
      // 车位列表
      {
        path: '/car/carSpaceList',
        component: () => import('@/pages/car/carSpace/carSpaceList')
      },
      // 车位与车辆绑定
      {
        path: '/car/carSpaceBindingCar',
        component: () => import('@/pages/car/carSpace/carSpaceBindingCar')
      },
      // 车位租赁
      {
        path: '/car/carSpaceLease',
        component: () => import('@/pages/car/carSpace/carSpaceLease')
      },

      // 车位过户
      {
        path: '/car/carSpaceTransfer',
        component: () => import('@/pages/car/carSpace/carSpaceTransfer')
      },

      // 车位管理费
      {
        path: '/car/carSpaceCost',
        component: () => import('@/pages/car/carSpace/carSpaceCost')
      },
      // 入住审批
      {
        path: '/approvalForCheckIn',
        name: '入住审批',
        component: () => import('@/pages/approvalForCheckIn/approvalForCheckIn')
      },
      // 入住审批
      {
        path: '/batchImport',
        component: () => import('@/pages/batchImport')
      },
      // 巡查类别=====================================
      //列表
      {
        path: '/PatrolTypeList',
        component: () => import('@/pages/Patrol/PatrolType/list.vue')
      },
      // 新增
      {
        path: '/PatrolTypeAdd',
        component: () => import('@/pages/Patrol/PatrolType/add.vue')
      },
      // 生成巡查吗
      {
        path: '/PatrolTypeGenerate',
        component: () => import('@/pages/Patrol/PatrolType/generate.vue')
      },
      // 生成巡查码  ————总的详情
      {
        path: '/generateDetailAll',
        component: () => import('@/pages/Patrol/PatrolType/generateDetailAll.vue')
      },
      // =====================================巡查类别
      // 巡查二维码列表
      {
        path: '/PatrolQRcodeList',
        component: () => import('@/pages/Patrol/PatrolQRcode/list.vue')
      },
      // 巡查二维码详情和修改
      {
        path: '/PatrolQRcodeDetail',
        component: () => import('@/pages/Patrol/PatrolQRcode/detail.vue')
      },
      // 巡查记录列表
      {
        path: '/PatrolRecordList',
        component: () => import('@/pages/Patrol/PatrolRecord/list.vue')
      },
      {
        path: '/PatrolRecordDetail',
        component: () => import('@/pages/Patrol/PatrolRecord/detail.vue')
      },
      // 巡查任务 列表
      {
        path: '/patrolTaskList',
        component: () => import('@/pages/Patrol/patrolTask/patrolTaskList.vue')
      },
      // 巡查任务 新增
      {
        path: '/patrolTaskAdd',
        component: () => import('@/pages/Patrol/patrolTask/patrolTaskAdd.vue')
      },
      // 巡查任务 详情
      {
        path: '/patrolTaskDetail',
        component: () => import('@/pages/Patrol/patrolTask/patrolTaskDetail.vue')
      },




      {
        path: '/largeScreenUpdate',
        component: () => import('@/pages/largeScreen/largeScreenUpdate.vue')
      },

      {
        path: '/largeScreenDetail',
        component: () => import('@/pages/largeScreen/largeScreenDetail.vue')
      },
      {
        path: '/companyLargeList',
        component: () => import('@/pages/largeScreen/companyLargeList.vue')
      },
      {
        path: '/companyLargeDetail',
        component: () => import('@/pages/largeScreen/companyLargeDetail.vue')
      },
      {
        path: '/companylargeScreenUpdate',
        component: () => import('@/pages/largeScreen/companylargeScreenUpdate.vue')
      },
      {
        path: '/appUpdateList',
        component: () => import('@/pages/appUpdate/list.vue')
      },
      {
        path: '/appUpdateAdd',
        component: () => import('@/pages/appUpdate/Add.vue')
      },
    ]
  }
]



const router = new Router({
  mode: 'history',
  routes
})

router.beforeEach((to, from, next) => {
  let logOnUser = JSON.parse(sessionStorage.getItem('logOnUser'))

  if (to.path != '/login' && to.path != '/SelectCompany') {
    if (logOnUser) {

      if (to.path == '/largeScreen') {// 如果点击数据大屏 直接新开界面
        let url = ''
        if (defaultUrl.indexOf('home') > -1) { //如果是公网
          if (logOnUser.unitType == 'agency') {
            url = `http://datav.quich.com.cn/view/1825734403616272386?token=${logOnUser.token}&account=${logOnUser.account}`
          } else if (logOnUser.unitType == 'company') {
            url = `http://datav.quich.com.cn/view/1831937359586349058?token=${logOnUser.token}&account=${logOnUser.account}`
          }
        } else {
          if (logOnUser.unitType == 'agency') {
            url = `http://192.168.124.123:8018/view/1825734403616272386?token=${logOnUser.token}&account=${logOnUser.account}`
          } else if (logOnUser.unitType == 'company') {
            url = `http://192.168.124.123:8018/view/1831937359586349058?token=${logOnUser.token}&account=${logOnUser.account}`
          }
        }
        console.log(url, '大屏');
        window.open(url)
        return
      }
      if (to.path == '/largeScreenConfiguration') {// 如果点击数据大屏的配置界面 直接新开界面
        let url = ''
        if (defaultUrl.indexOf('home') > -1) { //如果是公网
          url = `http://datav.quich.com.cn/?token=${logOnUser.token}&account=${logOnUser.account}`
        } else {
          url = `http://192.168.124.123:8018/?token=${logOnUser.token}&account=${logOnUser.account}`
        }
        console.log(url, '大屏配置');
        window.open(url)
        return
      }
      next()
    } else {
      alert('请先登录')
      next('/login')
    }
  } else {
    next()
  }
})
export default router



